package com.learn.algorithm_may_1;

import java.util.stream.IntStream;

/**
 * Created by QI.
 * 2020/5/8 21:20
 */
public class TestFoo {

    public static void main(String[] args) {
        IntStream.range(0, 10).forEach((i) -> {
            new TestFoo().test();
            System.out.println();
        });
    }

    public void test(){
        Foo foo = new Foo();

        Runnable r1 = () -> System.out.print(foo.toString()+ "-" + 1);
        Runnable r2 = () -> System.out.print(foo.toString()+ "-"  + 2);
        Runnable r3 = () -> System.out.print(foo.toString()+ "-"  + 3);

        //- 虽然调用顺序是3/2/1，但是输出结果要求是1/2/3
        new Thread( () -> {
            try {
                foo.third(r3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        new Thread( () -> {
            try {
                foo.second(r2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        new Thread( () -> {
            try {
                foo.first(r1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

    }

}
